class Solution {
public:
    string reverseStr(string s, int k) {
        int n = s.size();
        int pos1 = 0,pos2 = k;
        while(pos1 < n){
            int left = pos1,right = min(n,pos2) - 1;
            while(left < right){
                swap(s[left++],s[right--]);
            }
            pos1 += 2*k,pos2 +=2*k;
        }
        return s;
    }
};